#import "SEGSendsmscodenoimgcodeManager.h"

#if __has_include(<Commom/SEGModel.h>)
#import <Commom/SEGModel.h>
#else
#import "SEGModel.h"
#endif
#if __has_include(<Commom/SEGHTTPBusinessManager.h>)
#import <Commom/SEGHTTPBusinessManager.h>
#else
#import "SEGHTTPBusinessManager.h"
#endif

static id _sendSmsCodeNoImgCodeManager;
static dispatch_once_t onceToken;

@implementation SEGSendsmscodenoimgcodeManager
#pragma mark - SINGLE----BEGIN----
+(instancetype)sharedManager{
    dispatch_once(&onceToken, ^{
        _sendSmsCodeNoImgCodeManager = [[self alloc] init];
    });
    return _sendSmsCodeNoImgCodeManager;
}

+(void)destroyResource{
    onceToken = 0;
    _sendSmsCodeNoImgCodeManager = nil;
}

#pragma mark - SINGLE----END----

#pragma mark - HTTP----BEGIN----

/// 获取短信验证码
/// @see http://192.168.1.11:9090/html/web/controller/share/share.html#5ef1d2b4726846c8c24d4e76
/// @param tel 手机号
/// @param businessCode 短信业务编码
/// @param organId 组织机构ID（organId和accountCode二者必填一个）
/// @param accountCode 短信账户编码
-(void)requestSendsmscodenoimgcodeWithTel:(NSString*)tel businessCode:(NSString*)businessCode organId:(NSString*)organId accountCode:(NSString*)accountCode finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:tel forKey:@"tel"];
    [params setValue:businessCode forKey:@"businessCode"];
    
    // organId和accountCode二者必填一个
    [params setValue:organId forKey:@"organId"];
    [params setValue:accountCode forKey:@"accountCode"];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-sso/v1/sms/sendSmsCodeNoImgCode",nil];
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        
        self.sendSmsCodeNoImgCode = [SEGSendsmscodenoimgcodeModel yy_modelWithDictionary:result];
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
}
#pragma mark - HTTP----END----

#pragma mark - GETTER----BEGIN----
-(SEGSendsmscodenoimgcodeModel *)sendSmsCodeNoImgCode{
    if (!_sendSmsCodeNoImgCode) {
        _sendSmsCodeNoImgCode = [[SEGSendsmscodenoimgcodeModel alloc]init];
    }
    return _sendSmsCodeNoImgCode;
}
#pragma mark - GETTER----END----
@end
